﻿using HamcoWcs.Contract.ContractMes;
using HamcoWcs.Models.Common.Enums;
using HamcoWcs.Service.Common;
using System;
using System.Collections.Generic;
using System.Linq;

namespace HamcoWcs.Service.Mes
{
    [AutoInject(typeof(IMesMsgParserFactory), InjectType.Scope)]
    public class MesMsgParserFactory : IMesMsgParserFactory
    {
        public IEnumerable<IMesMsgParser> Parsers { get; }

        public MesMsgParserFactory(IEnumerable<IMesMsgParser> parsers)
        {
            Parsers = parsers;
        }

        public IMesMsgParser GetParser(string eventName)
        {
            eventName = eventName.ToUpper().Trim();
            return Parsers.FirstOrDefault(p => p.EventName.Equals(eventName,StringComparison.OrdinalIgnoreCase));
        }
    }
}
